import java.util.*;

/**
 * Author     :Dsi
 * Date       : 2021/12/2 18:57
 * Description:该类用于复习三种集合的迭代器
 */

public class Demo01 implements Cloneable {
    public static  void main(String[] args)  {
        //me();//List集合迭代遍历
        //me2();//set集合迭代遍历
        me3();//map集合迭代遍历
    }

    private static void me3() {
        HashMap<String,Integer> hm=new HashMap<String, Integer>();
        hm.put("jack",23);
        hm.put("jack1",24);
        hm.put("jack2",25);
        System.out.println(hm);
        Set<Map.Entry<String, Integer>> entries = hm.entrySet();
        Iterator<Map.Entry<String, Integer>> iterator1 = entries.iterator();
        while(iterator1.hasNext()){
            Map.Entry<String, Integer> next = iterator1.next();


            System.out.println(next.getKey() + next.getValue());
        }
        for (Object a:entries
             ) {
            System.out.println(a);
        }
        Set<String> strings = hm.keySet();
        System.out.println(strings);
        Iterator<String> iterator = strings.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next+"+"+hm.get(next));
        }



    }

    private static void me2() {
        HashSet<String> hs=new HashSet();
        hs.add("as");
        hs.add("asf");
        hs.add("aas");
        hs.add("ads");
        System.out.println(hs);
        Iterator iterator = hs.iterator();
        for (int i = 0; iterator.hasNext(); i++) {
            System.out.println(iterator.next());
        }
        System.out.println();
        for (String s: hs
             ) {
            System.out.println(s);
        }
    }

    private static void me() {
        ArrayList<Integer> a=new ArrayList();
        for (int i = 0; i <10; i++) {
            a.add(Integer.valueOf( new Random().nextInt()));
        }
        //高效循环遍历
        for (Integer a1:a
             ) {
            System.out.println(a1);
        }
        System.out.println();
        //迭代器遍历
        Iterator<Integer> iterator = a.iterator();
        for (int i = 0; iterator.hasNext(); i++) {
            System.out.println(iterator.next());
        }

    }
}
